﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;

namespace QA_System
{
    public class NPanaphoraCondition
    {
        static XMLVerbConnection verbconn = new XMLVerbConnection();

        static XMLNounConnection nounconn = new XMLNounConnection();

        static public bool INumberAgree(WordStruct pronouns, WordStruct reference)
        {
            try
            {
                bool result = false;
                if (pronouns.WordSubMean.Contains("Sing") && (reference.WordSubMean.Contains("Sing"))) result = true;
                else if (reference.WordSubMean.Contains("Plu")&& pronouns.WordSubMean.Contains("Plu")) result = true;
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        static public bool IGenderAgree(WordStruct pronouns, WordStruct reference)
        {
            try
            {
                bool result = false;
                
                if (pronouns.WordSubMean.Contains("People") && (reference.WordSubMean.Contains("People")))
                {
                    if (reference.WordSubMean.Contains("X?")) result = true;
                    else
                    {
                        /* code cu
                        if (pronouns.WordSubMean.Contains("XX") && (reference.WordSubMean.Contains("XX"))) result = true;
                        else if (reference.WordSubMean.Contains("XO")) result = true;
                         * */
                        //Vinh sua lai
                        if (pronouns.WordSubMean.Contains("XX") && (reference.WordSubMean.Contains("XX"))) result = true;
                        else if (pronouns.WordSubMean.Contains("XO") && (reference.WordSubMean.Contains("XO"))) result = true;
                        else result = false;
                    }
                }
                else
                {
                    if (reference.WordSubMean.Contains("Things")&&(pronouns.WordSubMean.Contains("Thing"))) result = true;
                }
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        static public bool IVerbAgree(WordStruct referennce,WordStruct verb, bool asObject)
        {
            try
            {
                bool result = false;
                verb.Word = verb.Word.ToLower();
                //referennce.Word = referennce.Word.ToLower();
                
                if (asObject)
                {
                    string objectType = verbconn.GetTypeofObject(verb, "");
                    string typeOfNoun = nounconn.GetWordType(referennce, "");
                    if ((!string.IsNullOrEmpty(typeOfNoun))&&(objectType.Contains(typeOfNoun))) result = true;
                }
                else
                {
                    string subjectType = verbconn.GetTypeofSubject(verb,"");
                    string typeOfNoun = nounconn.GetWordType(referennce,"");
                    if ((!string.IsNullOrEmpty(typeOfNoun)) && (subjectType.Contains(typeOfNoun))) result = true;
                    if ((!string.IsNullOrEmpty(typeOfNoun)) && verb.Word=="là" && typeOfNoun=="People") result = true;
                }
               
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        static public bool IVerbDisjoint(WordStruct reference,WordStruct verb, SentenceStruct sentences)
        {
            try
            {
                bool result = false;
                WordStruct wsSubject = sentences.GetSubjectofVerb(verb);
                if (verbconn.IsAllowDisjoint(verb, "")) result = true;
                else
                {
 
                }
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
